// api
import { Ref } from 'vue'
import { doGetSetMealBasicInfo } from '../apis/index'

import type { StorageSku } from '@/pluginPackage/goods/commodityInfo/types'
import type { SetMealBasicInfoVO } from '@/apis/good/model'
import type { TParamsSetMealBasicInfo } from '../apis/model/api-params-types'

interface returnHooksOfSetMeal {
  doRequest: (params: TParamsSetMealBasicInfo) => void
  setMealBasicInfo: Ref<SetMealBasicInfoVO[]>
}
type HookCallback = (params: any) => void
/**
 * 套餐hooks
 * @param {Ref} currentSku
 * @param {HookCallback} callback
 */
export default (currentSku: Ref<StorageSku>, callback: HookCallback): returnHooksOfSetMeal => {
  // 套餐基本信息
  const setMealBasicInfo = ref<SetMealBasicInfoVO[]>([])

  const doRequest = () => {
    console.log('currentSku', currentSku)
    // handleGetSetMealBasicInfo(params)
  }
  const handleGetSetMealBasicInfo = async (params: TParamsSetMealBasicInfo) => {
    const { code, data, msg }: { code: number; data?: SetMealBasicInfoVO[]; msg: string } = await doGetSetMealBasicInfo(params)
    if (code !== 200 || !data) return uni.showToast({ title: `${msg || '获取套餐基本信息失败'}`, icon: 'none' })
    setMealBasicInfo.value = data
  }
  return {
    doRequest,
    setMealBasicInfo,
  }
}
